package com.finiac.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.finiac.dao.StudentDAO;
import com.finiac.model.Product;
import com.finiac.model.Student;

public class StudentController extends MultiActionController {
	StudentDAO studentDAO;
	
	
	public void setStudentDAO(StudentDAO studentDAO) {
		this.studentDAO = studentDAO;
	}

	public ModelAndView addStudentPage(HttpServletRequest request, HttpServletResponse response)throws Exception
	{
		ModelMap modelMap = new ModelMap();
		modelMap.addAttribute("studentList",studentDAO.listStudent());
		return new ModelAndView("studentEntry",modelMap);
	}
	
	public ModelAndView addStudent(HttpServletRequest request, HttpServletResponse response,Student student)throws Exception
	{
		
		student.setIsActive(1);
		studentDAO.saveStudent(student);
		return new ModelAndView("redirect:addStudentPage.htm");
	}
	public void deleteStudent(HttpServletRequest request, HttpServletResponse response)throws Exception
	{
		int admissionNo=Integer.parseInt(request.getParameter("admissionNo"));
		Student student= new Student();
		student=studentDAO.selectByAdmissionNo(admissionNo);
		student.setIsActive(0);
		studentDAO.saveStudent(student);
	}
	public ModelAndView updateStudentPage(HttpServletRequest request, HttpServletResponse response)throws Exception
	{
		int admissionNo=Integer.parseInt(request.getParameter("admissionNo"));
		Student student=new Student();
		student=studentDAO.selectByAdmissionNo(admissionNo);
		return new ModelAndView("updateStudent","student",student);
	}
	
	
}
